#!/usr/bin/env bash

# ----------------------------------------------------------------------
# Filename	:  01-usermanage.sh
# Version	:  2.0
# Date		:  2024/05/14
# Author	:  yaoxiyao
# Email		:  yaoxiyao@kylinsec.com.cn
# Function	:  用户管理-命令
# Out		:
#              0 => TPASS
#              1 => TFAIL
#              other=> TCONF
# ----------------------------------------------------------------------

# 测试主题
Title_Env_LTFLIB="用户管理-命令"

HeadFile_Source_LTFLIB="${LIB_SSHAUTO}"

TEST_USER1="ltfdesktop01"
PASSWD_1="olleH717.12.#$"
USER_IP="localhost"
AddUserNames_LTFLIB="${TEST_USER1}"
AddUserPasswds_LTFLIB="${PASSWD_1}"
ETC_SHADOW_FILE="/etc/passwd"

## TODO : 个性化,初始化
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestInit_LTFLIB() {
    # 创建临时文件
    test_userdel="${TmpTestDir_LTFLIB}/filedel"
    echo "Hello LTF" >${test_userdel}
    CommRetParse_FailDiy_LTFLIB ${ERROR} "创建文件失败${test_userdel}"
    # 配置免密登录
    SshAuto_OneConfig_LTFLIB "${USER_IP}" "${TEST_USER1}" "${PASSWD_1}"
    TestRetParse_LTFLIB "配置免密登录" "True" "no" "yes"

    SshAuto_SetIpUser_LTFLIB "${USER_IP}" "${TEST_USER1}"
    TestRetParse_LTFLIB "设置默认IP和用户名" "True" "no" "yes"
    return $TPASS
}

## TODO : 清理函数
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestClean_LTFLIB() {
    return $TPASS
}

## TODO : 测试用例集
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
Testsuite_LTFLIB() {
    testcase_1
    return $TPASS
}

## TODO : 用户管理-命令
testcase_1() {
    sudo userdel -rf "${TEST_USER1}" &>/dev/null
    cat "${ETC_SHADOW_FILE}" | grep "${TEST_USER1}"
    CommRetParse_LTFLIB "cat ${ETC_SHADOW_FILE} |grep ${TEST_USER1}" "False" "yes"

}

#----------------------------------------------#

source "${LIB_LTFLIB}"
Main_LTFLIB $@
